<?php
namespace wechat;

class Message extends Base
{
	
	/**
	* 消息管理-  发送客服消息-图文消息	2017-02-25
	*/
	public function transfernews($news,$openid,$access_token,$attach = array()){
		$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=$access_token";
		$data = array(
			'touser'	=> $openid,
			'msgtype'	=> 'news',
			'news'		=> array('articles'=>$news)
		);
		$result = httpdata($url,$data);
		
		!isset($attach['uid']) && $attach['uid'] = 0;
		apilog($attach['uid'],'wechat','sendtemplate',$url,$data,$result);
		
		return $result;
	}
	
	/**
	* 消息管理-  发送客服消息-文本消息	2017-10-15
	*/
	public function transfertext($text,$openid,$access_token,$attach = array()){
		$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=$access_token";
		$data = array(
			'touser'	=> $openid,
			'msgtype'	=> 'text',
			'text'		=> array('content'=>$text)
		);	
		$result = httpdata($url,$data);
		
		!isset($attach['uid']) && $attach['uid'] = 0;
		apilog($attach['uid'],'wechat','sendtemplate',$url,$data,$result);
		
		return $result;
	}
	
	/**
	* 发送模板消息	2017-10-15
	*/
	public function template($data,$access_token,$attach = array()){
		$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=$access_token";
		$result = httpdata($url,$data);
		
		!isset($attach['uid']) && $attach['uid'] = 0;
		apilog($attach['uid'],'wechat','sendtemplate',$url,$data,$result);
		
		return $result;
	}
	
}